package com.zhimu.activemq_demo.activemq.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.TextMessage;

/**
 * @Author: Alvin
 * @Date: 2019/6/23 01:38
 * @Description
 */
@Service
public class SpringMQ_Produce {

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SpringMQ_Produce produce = (SpringMQ_Produce) applicationContext.getBean("springMQ_Produce");
        produce.jmsTemplate.send((session)->{
            TextMessage textMessage = session.createTextMessage("*******spring整合activemq .......");
            return textMessage;
        });

        System.out.println("发送消息成功");
//        produce.jmsTemplate.send(new MessageCreator() {
//            @Override
//            public Message createMessage(Session session) throws JMSException {
//                TextMessage textMessage = session.createTextMessage("*******spring整合activemq .......");
//                return textMessage;
//            }
//        });
    }
}
